package zbf.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
import zbf.com.Entity.LRU_Cache;
import zbf.com.Entity.TestData;
import zbf.com.utils.CacheThreadTest;

@RestController
@RequestMapping("/data")
//@Scope("prototype")
public class DataController {

    @Autowired
    LRU_Cache cache;
    @Autowired
    CacheThreadTest cacheThreadTest;

    // 该接口 接收到数据后 什么都不做
    @RequestMapping(value = "/sendDataDoNothing",method = RequestMethod.POST)
    public void sendDataDoNothing(String id,String name){
        System.out.println("/sendDataDoNothing");
    }

    /** 接受到数据后 将其封装后 插入缓存
     * @描述:
     * @author: 凡
     * @date: 2021/7/5 9:34
     */
    @RequestMapping(value = "/putDateToCache",method = RequestMethod.POST)
    public void putDateToCache(String id,String name){
        System.out.println("/putDateToCache---> id:"+id);
        TestData data = new TestData(id,name);
        cache.put(id,data);
    }




    @RequestMapping("/toString")
    public String getCache(){
        System.out.println("/toString");
        return cache.toString();
    }
    @RequestMapping("/del")
    public void delCache(){
        System.out.println("/del");
        cache.delAllNode();
    }

    @RequestMapping("/test")
    public void doTest(Integer threadNUM,Integer threadLoop,String str){
        System.out.println("/test");
        cacheThreadTest.StartThread(threadNUM,threadLoop,str);
    }

}
